//
//  ServerController.h
//  Memento 3.0
//
//  Created by Chris Maddocks on 10-08-01.
//  Copyright 2010 Team Memento. All rights reserved.
//
//  Portions adapted from SpeakHereController.h; see http://developer.apple.com/iphone/library/samplecode/SpeakHere/Listings/Classes_SpeakHereController_mm.html#//apple_ref/doc/uid/DTS40007802-Classes_SpeakHereController_mm-DontLinkElementID_20
//
//  Description: This class mediates between a PhotoCollection and an external Memento Server.  It supports user authentication,
//  catalog listing, catalog uploading, and retrieval or storage of individual memory components (photo or audio).
//  Please see the Memento Server design document for details on the communications protocol used.
//
//  10-08-04: Fix bug with invalid selector in backup (C. Maddocks)
//  10-08-03: Add ServerControllerDelegate protocol for relaying progress  (C. Maddocks)
//  10-08-01: Initial creation (C. Maddocks)

#import <Foundation/Foundation.h>

#define kComponentMetadata	0
#define kComponentImage		1
#define	kComponentAudio		2

@class Memory;
@class PhotoCollection;

@protocol ServerControllerDelegate <NSObject>
@optional
- (void)progressChanged:(int)value ofMaximum:(int)maxValue;
@end


@interface ServerController : NSObject {
	PhotoCollection *photoCollection;
	NSString	*sessionToken;
	NSURL		*serverURL;
	id<ServerControllerDelegate> delegate;
}
@property (nonatomic, retain) PhotoCollection *photoCollection;
@property (nonatomic, retain) NSURL *serverURL;
@property (nonatomic, retain) NSObject *delegate;

- (id)initWithURL:(NSURL *)url usingPhotoCollection:(PhotoCollection *)aPhotoCollection delegate:(NSObject *)aDelegate;

- (BOOL)authenticateUser:(NSString *)username withPassword:(NSString *)password usingScript:(NSString *)script;
- (BOOL)createUser:(NSString *)username withPassword:(NSString *)password;
- (BOOL)loginWithUsername:(NSString *)username withPassword:(NSString *)password;

- (BOOL)uploadMemory:(Memory *)memory;

- (NSArray *)retrieveMemoryList;
- (Memory *)retrieveMemory:(int)memoryId;
- (NSString *)retrieveComponent:(int)component forMemory:(Memory *)memory;
- (void)retrieveMemories;
- (int)backupMemories;

- (BOOL)clearCollection;


@end
